package commandmode.impl;

import commandmode.base.BaseCommand;
import commandmode.entity.CeilingFan;

/**
 * 吊扇中速转动按钮命令
 * @author yaojianfeng
 */
public class CeilingFanMediumCommand implements BaseCommand {
    CeilingFan ceilingFan;
    /**
     * 增加局部状态以便于追踪吊扇之前的速度
     */
    int prevSpeed;

    public CeilingFanMediumCommand(CeilingFan ceilingFan) {
        this.ceilingFan = ceilingFan;
    }

    /**
     * 每种命令均实现该接口
     */
    @Override
    public void execute() {
        prevSpeed = ceilingFan.getSpeed();
        ceilingFan.setMedium();
    }

    /**
     * 撤销功能
     * 回退到上一步的动作状态
     */
    @Override
    public void undo() {
        if (prevSpeed == CeilingFan.HIGH){
            ceilingFan.setHigh();
        }else if (prevSpeed == CeilingFan.MEDIUM){
            ceilingFan.setMedium();
        }else if (prevSpeed == CeilingFan.LOW){
            ceilingFan.setLow();
        }else if (prevSpeed == CeilingFan.OFF){
            ceilingFan.setOff();
        }

    }


}
